package com.yitong.main.service;

import com.yitong.main.jpa.YpluginPropertiesRepository;
import com.yitong.main.jpa.YpluginRepository;
import com.yitong.spiboot.YpluginServer;
import com.yitong.spiboot.entity.Yplugin;
import com.yitong.spiboot.entity.YpluginProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
//@Scope("prototype")

public class YpluginServerImpl implements YpluginServer {
    @Autowired
    YpluginRepository ypluginRepository;
    @Autowired
    YpluginPropertiesRepository ypluginPropertiesRepository;


    public Yplugin getYplugin(String yid) {
        return ypluginRepository.findById( yid ).orElseThrow( () -> new RuntimeException( "spring boot插件不存在！！！" ) );
    }

    public List <YpluginProperties> getYpluginProperties(String pid) {
        YpluginProperties ypluginProperties = new YpluginProperties();
        ypluginProperties.setPid( pid );
        Example <YpluginProperties> ypluginPropertiesExample = Example.of( ypluginProperties );
        return ypluginPropertiesRepository.findAll( ypluginPropertiesExample );
    }
}
